<template>
  <div class="myheader">
    <!-- 头部 -->
    <div class="header">
      <img class="img1"
           src="../assets/img/img2/退出.png"
           @click="logout">
      <span>
        <slot></slot>
      </span>
      <div class="gh">{{username}}</div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'myheader',
  data() {
    return {
      username: ''
    }
  },
  mounted() {
    this.initUserInfo()
  },
  methods: {
    // 个人信息初始化
    initUserInfo() {
      this.username = $cookies.get('totalInfo').UserInfo.UserName
    },
    // 退出登录
    logout() {
      // 退出提示
      this.$Dialog({
        title: '提示',
        message: '是否退出登录?'
      })
        .then(() => {
          // on confirm
          // 清理缓存
          $cookies.remove('totalInfo')
          this.$store.commit('updateToken', null)
          // this.$store.commit('updateActive', null)
          // 跳转
          this.$router.push('/login')
        })
        .catch(err => {
          // on cancel
          console.log(err)
        })
    }
  }
}
</script>

<style lang="less" scoped>
.header {
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 99;
  background-color: rgba(0, 90, 170, 0.7);
  font-size: 18px;
  font-weight: 600;
  color: #fff;
  height: 44px;
  line-height: 44px;
  border-bottom: 1px solid #ddd;
  text-align: center;

  .gh {
    font-size: 14px;
    position: absolute;
    top: 0;
    right: 16px;
  }

  .img1 {
    width: 16px;
    height: 16px;
    position: absolute;
    top: 13px;
    left: 16px;
  }
}
</style>